import {Component, Inject} from '@angular/core';
import {AbstractControl, FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {HttpService} from '../../../services/http.service';
import {ActivatedRoute, NavigationEnd, Params, Router} from '@angular/router';
import {NbToastrService} from '@nebular/theme';
import {NativeService} from '../../../services/native.service';
import {StorageService} from '../../../services/storage.service';
import {UserService} from '../../../services/user.service';
import {StorageKey} from '../../../storage.key';


@Component({
    selector: 'ngx-login',
    templateUrl: './login.component.html',
    styleUrls: ['./login.component.scss'],
})
export class LoginComponent {
    // loginForm: FormGroup;
    // mobile: AbstractControl;
    //  password: AbstractControl;
    //
    // constructor(
    //     @Inject(ActivatedRoute) private activatedRoute: ActivatedRoute,
    //     private fb: FormBuilder,
    //     private httpService: HttpService,
    //     public  router: Router,
    //     private nativeService: NativeService,
    //     private storageService: StorageService,
    //     private userService: UserService,
    // ) {
    //     this.loginForm = this.fb.group({
    //         mobile: new FormControl('', {
    //             validators: [Validators.required, Validators.pattern(/^1[3456789]\d{9}$/)],
    //         }),
    //         /*password: new FormControl('12345678i', {
    //             validators: [Validators.required, Validators.pattern(
    //                 /((?=.*\d)(?=.*\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))(?!^.*[\u4E00-\u9FA5].*$)^\S{8,16}$/)],
    //         }),*/
    //         password: new FormControl('', [Validators.required]),
    //     });
    //     this.mobile = this.loginForm.controls.mobile;
    //     this.password = this.loginForm.controls.password;
    //     this.activatedRoute.params.subscribe((params: Params) => {
    //         console.log(this.activatedRoute);
    //     });
    //     const token = this.storageService.get(StorageKey.TOKEN);
    //     console.log(token);
    //     // if (token) {
    //     //     this.storageService.clear();
    //     // }
    //     // console.log(token);
    // }
    //
    // async login() {
    //     const loginParam = this.loginForm.getRawValue();
    //     console.log(loginParam);
    //     const userInfo = await this.userService.login(loginParam);
    //     console.log(userInfo);
    //     const token = userInfo.token;
    //     console.log(token);
    //         if (token) {
    //             this.storageService.set(StorageKey.TOKEN, token);
    //             this.storageService.set(StorageKey.USER_INFO, userInfo);
    //             this.router.navigateByUrl('/home/home-page/list');
    //             this.nativeService.showSuccess('登录成功');
    //         }
    // }
}
